<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>

<title>检查物料编码有效性</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
</head>
<body>
	<div id="msg" align="center" style="padding-top: 40px;">
		正在验证物料编码……</div>
	<script type="text/javascript">
	var upWindow = window.parent.frames["zwIframe"];
	if (!upWindow) {
    upWindow = window.parent.frames["componentDiv"].frames["zwIframe"];
}
	var designClass = "design_class", hideClass = "hide_class", browseClass = "browse_class", addClass = "add_class", editClass = "edit_class";
	
	function fy_dialog_close(){
		window.parent.$(".mask").remove();
		window.parent.parent.$(".layui-layer-iframe").parent().find(".layui-layer-close").trigger("click");
	}
		function getUpFieldsByFieldval(name) {
			return upWindow.$("[fieldval*='displayName:\"" + name + "\"']");
		}

		function getUpFieldValue(field) {
			var fieldVal = field.attr("fieldVal");
			var editTag = field.hasClass(editClass);
			var browseTag = field.hasClass(browseClass);
			var addTag = field.hasClass(addClass);
			if (fieldVal != null && typeof (fieldVal) != 'undefined') {
				fieldVal = eval("(" + fieldVal + ")");
			} else {
				return null;
			}
			var obj = new Object();
			obj.displayName = fieldVal.displayName;
			obj.name = fieldVal.name;
			var tag = true;
			switch (fieldVal.inputType) {
			case "text":
			case "textarea":
				if (editTag) {
					obj.value = field.find("#" + fieldVal.name).val();
				} else if (browseTag) {
					obj.value = fieldVal.value;
				} else if (addTag) {
					obj.value = field.find("#" + fieldVal.name).val();
				}
				break;
			default:
				tag = false;
			}
			if (obj.value != undefined) {
				obj.value = obj.value.replace("\r\n", ";");
				obj.value = obj.value.replace("\n", ";");
			}
			return obj;
		}
		
		function setUpFieldValue2(field, value, displayValue, index) {
				var fieldVal = field.attr("fieldVal");
				var editTag = field.hasClass(editClass);
				var browseTag = field.hasClass(browseClass);
				var addTag = field.hasClass(addClass);
				/* console.log(field)
				console.log(fieldVal) */
				if (fieldVal != null && typeof (fieldVal) != 'undefined') {
					fieldVal = eval("(" + fieldVal + ")");
				} else {
					return null;
				}
				var tag = true;
				if(!field.find("#" + fieldVal.name))
					{
					console.log("#" + fieldVal.name)
					}
				switch (fieldVal.inputType) {
				case "text":
				case "textarea":
					if (editTag) {
						field.find("#" + fieldVal.name).val(value);
						field.find("#" + fieldVal.name).trigger("blur");
					} else if (addTag) {
						field.find("#" + fieldVal.name).val(
								field.find("#" + fieldVal.name).val() + value);
						field.find("#" + fieldVal.name).trigger("blur");
					}
					break;
				case "date":
					if (editTag) {
						field.find("#" + fieldVal.name).val(value);
						field.find("#" + fieldVal.name).trigger("blur");
					}
					break;
				}
		}

		
		var xmlObj = null;
		var DifferentiateForm = false;
		/* var consultNoInputArray = getUpFieldsByFieldval("参考号");
		var cuNameInputArray = getUpFieldsByFieldval("单号");
		var personInputArray = getUpFieldsByFieldval("参考号填写");
		
		var customerCodeInputArray = getUpFieldsByFieldval("客户代码");
		var customerNameInputArray = getUpFieldsByFieldval("客户名称");
		var motorcycleTypeInputArray = getUpFieldsByFieldval("车型");
		var productNumberInputArray = getUpFieldsByFieldval("产品编号");
		var partNumberInputArray = getUpFieldsByFieldval("零件号");
		var pieceNumberInputArray = getUpFieldsByFieldval("片数");
		
		var boxesNumberInputArray = getUpFieldsByFieldval("箱数");
		var packingBoxTypeInputArray = getUpFieldsByFieldval("包装箱型");
		var weightInputArray = getUpFieldsByFieldval("重量"); */
		//alert(personInputArray.length);
		//materialCode.push(getUpFieldValue(personInputArray.eq(0)).value);
/* 	if(consultNoInputArray.length>0){
	length = consultNoInputArray .length; 
		}     */

	function addOrDelRepeat(name, newLength) {
	var fields = getUpFieldsByFieldval(name);
		var oldLength = fields.length;

	

		var tbody = getUpFieldsByFieldval(name).eq(0).parent();
		while (!tbody.is("tbody")) {
			tbody = tbody.parent();
		}
		for ( var i = 0, length = Math.abs(newLength - oldLength); i < length; i++) {
			if (newLength > oldLength) {
				upWindow.fy_addEmpty(tbody.children().last());
			} else {
				upWindow.fy_delCurrentRepeat(tbody.children().last());
			}
			
		}
	}
		function init() {		

		}
        var materialCode = [];
        var consultNoInputArray;
        var cuNameInputArray;
        var personInputArray;
        var customerCodeInputArray;
        var customerNameInputArray;
        var motorcycleTypeInputArray;
        var productNumberInputArray;
        var partNumberInputArray;
        var pieceNumberInputArray;
        var boxesNumberInputArray;
        var packingBoxTypeInputArray;
        var weightInputArray;
        
        var shippingDateArray;
        var	customerAddressArray;
        var	contactsPerson1Array;
        var	shippingCarrierArray;
        var	shippingCartypeArray;
        
		function load() {
			 materialCode ;
			 consultNoInputArray = getUpFieldsByFieldval("参考号");
			 cuNameInputArray = getUpFieldsByFieldval("单号");
			 personInputArray = getUpFieldsByFieldval("参考号填写");
			
			 customerCodeInputArray = getUpFieldsByFieldval("客户代码");
			 customerNameInputArray = getUpFieldsByFieldval("客户名称");
			 motorcycleTypeInputArray = getUpFieldsByFieldval("车型");
			 productNumberInputArray = getUpFieldsByFieldval("产品编号");
			 partNumberInputArray = getUpFieldsByFieldval("零件号");
			 pieceNumberInputArray = getUpFieldsByFieldval("片数");
			
			 boxesNumberInputArray = getUpFieldsByFieldval("箱数");
			 packingBoxTypeInputArray = getUpFieldsByFieldval("包装箱型");
			 weightInputArray = getUpFieldsByFieldval("重量");
			 materialCode.push(getUpFieldValue(personInputArray.eq(0)).value);
			 
			 shippingDateArray = getUpFieldsByFieldval("发货时间");
			 customerAddressArray = getUpFieldsByFieldval("送货地址");
			 contactsPerson1Array = getUpFieldsByFieldval("收货人");
			 shippingCarrierArray = getUpFieldsByFieldval("承运公司");
			 shippingCartypeArray = getUpFieldsByFieldval("承运车型");
			 
			//materialCode.push(getUpFieldValue(personInputArray.eq(0)).value);
			if (window.XMLHttpRequest) {
				xmlObj = new XMLHttpRequest();
			} else {
				if (window.ActiveXObject) {
					xmlObj = new ActiveXObject("Microsoft.XMLHTTP");
				} else {
					return;
				}
			}

			xmlObj.onreadystatechange = handleResponse;
			xmlObj.open("get",
					"./oa2mdmController.do?method=writeProductInfoJSP&productCode="+ materialCode.join(","), true);
			
			xmlObj.send();

		}
		
		function handleResponse() {
			
			if (xmlObj.readyState == 4) {//xmlObj loaded
				var success = false;
				if (xmlObj.status == 200) {
					//var datas = eval("[" + xmlObj.responseText + "]");
					var datas = JSON.parse(xmlObj.responseText);
					
				addOrDelRepeat("参考号",datas.length); 
				//setTimeout(function(){		
					for ( var i=0;i<datas.length;i++) {

						// 参考号
						setUpFieldValue2(getUpFieldsByFieldval("参考号").eq(i),datas[i].consult_no);	
							setUpFieldValue2(getUpFieldsByFieldval("单号").eq(i),datas[i].list_num);	
							 setUpFieldValue2(getUpFieldsByFieldval("客户代码").eq(i),datas[i].customer_code);	
							setUpFieldValue2(getUpFieldsByFieldval("客户名称").eq(i),datas[i].cuname);	
							 setUpFieldValue2(getUpFieldsByFieldval("车型").eq(i),datas[i].shipping_cartype);								 							 
							setUpFieldValue2(getUpFieldsByFieldval("产品编号").eq(i),datas[i].item_code);	
							setUpFieldValue2(getUpFieldsByFieldval("零件号").eq(i),datas[i].part_num);	
							setUpFieldValue2(getUpFieldsByFieldval("片数").eq(i),datas[i].piecenum);	
							
							setUpFieldValue2(getUpFieldsByFieldval("箱数").eq(i),datas[i].case_num);	
							setUpFieldValue2(getUpFieldsByFieldval("包装箱型").eq(i),datas[i].packing_per_case);	
							//setUpFieldValue2(getUpFieldsByFieldval("重量").eq(i),datas[i].shipping_date);
							setUpFieldValue2(getUpFieldsByFieldval("发货时间").eq(0),datas[0].shipping_date);
							setUpFieldValue2(getUpFieldsByFieldval("送货地址").eq(0),datas[0].customer_address);
							setUpFieldValue2(getUpFieldsByFieldval("收货人").eq(0),datas[0].contacts_person1);
							setUpFieldValue2(getUpFieldsByFieldval("承运公司").eq(0),datas[0].shipping_carrier);
							setUpFieldValue2(getUpFieldsByFieldval("承运车型").eq(0),datas[0].shipping_cartype);	
							setUpFieldValue2(getUpFieldsByFieldval("重量").eq(i),datas[i].box_height);	 	
							success = true; 
					}  
  					
  					if (!success) {
  						alert("请检查输入的參考号 ");
  					}
  					fy_dialog_close();
			//	},3000);	
    	       

    	      
			}

				
			}
		}

		load();
	</script>
</body>
</html>

</html>